package Events;

import Events.Composite_Events.Crashed;
import Events.Composite_Events.FindMoney;
import Events.Composite_Events.FoundCrookedEmployee;
import Events.Composite_Events.GasFire;
import Events.Composite_Events.PilotAirForceOne;
import shared.Consts;
import Events.Simple_Events.Simple_CardInterestRateChange;
import Events.Simple_Events.Simple_BalanceChange;
import server.ProfessionFactory.profession_type;
import java.util.ArrayList;
import java.util.EnumMap;

/**
 * Populates event lists for each player
 * @author Joel Garboden
 */
public class EventPopulator
{
  private ArrayList<BaseEvent> genericEventList;
  private EnumMap<profession_type, ArrayList<BaseEvent>> profEventList;

  /**
   * Populates all generic and profession event lists
   */
  public EventPopulator()
  {
    genericEventList = new ArrayList<>();

    profEventList = new EnumMap<>(profession_type.class);

    populateGenericEvents();

    populateProfessionEventLists();
  }

  /**
   * Returns a compilation of specified profession events with appended generic events
   * @param profID specific profession
   * @return profession events + generic events
   */
  public ArrayList<BaseEvent> makeEventListFor(profession_type profID)
  {
    ArrayList<BaseEvent> eventList = new ArrayList<>();

    eventList.addAll(profEventList.get(profID));

    eventList.addAll(genericEventList);

    return eventList;
  }

  /**
   * Populates the generic event list
   */
  private void populateGenericEvents()
  {
    genericEventList.add(new Simple_CardInterestRateChange(0, Consts.TWO_PERCENT));
    genericEventList.add(new FindMoney());
    genericEventList.add(new Simple_BalanceChange(0, Consts.TWO_PERCENT));
  }

  /**
   * Populates profession event lists
   */
  private void populateProfessionEventLists()
  {
    profEventList.put(profession_type.PILOT, populatePilot());

    profEventList.put(profession_type.ENTREPENEUR, populateEntrepeneur());
  }

  /**
   * Populates the event list for pilot profession
   * @return pilot profession event list
   */
  private ArrayList<BaseEvent> populatePilot()
  {
    ArrayList<BaseEvent> pilotEventList = new ArrayList<>();

    pilotEventList.add(new Crashed());
    pilotEventList.add(new PilotAirForceOne());
    pilotEventList.add(new FoundCrookedEmployee());

    return pilotEventList;
  }

  /**
   * Populates the event list for entrepeneur profession
   * @return pilot profession event list
   */
  private ArrayList<BaseEvent> populateEntrepeneur()
  {
    ArrayList<BaseEvent> entrepeneurEventList = new ArrayList<>();

    entrepeneurEventList.add(new FoundCrookedEmployee());
    entrepeneurEventList.add(new GasFire());

    return entrepeneurEventList;
  }
}
